<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>相交链表 - 算法详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #282c34;
            color: #abb2bf;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-block pre {
            padding: 1.5rem;
            overflow-x: auto;
        }
        .keyword { color: #c678dd; }
        .function { color: #61afef; }
        .string { color: #98c379; }
        .comment { color: #5c6370; font-style: italic; }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .badge {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 0.25rem 0.75rem;
            border-radius: 9999px;
            font-size: 0.875rem;
            font-weight: 500;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-4xl mx-auto text-center">
            <div class="mb-4">
                <i class="fas fa-code-branch text-5xl opacity-80"></i>
            </div>
            <h1 class="text-5xl font-bold mb-4" style="font-family: 'Noto Serif SC', serif;">相交链表</h1>
            <p class="text-xl opacity-90 leading-relaxed">探索双指针算法的优雅之美，寻找两条路径的交汇点</p>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        <!-- Problem Description Card -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
            <div class="flex items-center mb-6">
                <i class="fas fa-puzzle-piece text-3xl text-purple-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">题目描述</h2>
            </div>
            <div class="text-gray-700 leading-relaxed text-lg">
                <p><span class="drop-cap">找</span>出两个单链表相交的起始节点。如果两个链表不存在相交节点，返回 null。这道题目考察的是对链表结构的理解和双指针技巧的运用。</p>
                <div class="mt-6 grid grid-cols-1 md:grid-cols-3 gap-4">
                    <div class="bg-purple-50 rounded-lg p-4 text-center">
                        <i class="fas fa-list text-purple-600 text-2xl mb-2"></i>
                        <p class="text-sm text-gray-700">节点数目范围</p>
                        <p class="font-bold text-purple-700">[0, 10⁴]</p>
                    </div>
                    <div class="bg-purple-50 rounded-lg p-4 text-center">
                        <i class="fas fa-link text-purple-600 text-2xl mb-2"></i>
                        <p class="text-sm text-gray-700">相交定义</p>
                        <p class="font-bold text-purple-700">尾部共享节点</p>
                    </div>
                    <div class="bg-purple-50 rounded-lg p-4 text-center">
                        <i class="fas fa-ban text-purple-600 text-2xl mb-2"></i>
                        <p class="text-sm text-gray-700">特殊约束</p>
                        <p class="font-bold text-purple-700">保证无环</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Algorithm Visualization -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
            <div class="flex items-center mb-6">
                <i class="fas fa-project-diagram text-3xl text-purple-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">算法可视化</h2>
            </div>
            <div class="mermaid">
                graph LR
                    A1[A链表头] --> A2[节点A2] --> A3[节点A3] --> C1[交点]
                    B1[B链表头] --> B2[节点B2] --> C1
                    C1 --> C2[共享节点] --> C3[链表尾]
                    
                    style A1 fill:#667eea,stroke:#333,stroke-width:2px,color:#fff
                    style B1 fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff
                    style C1 fill:#f093fb,stroke:#333,stroke-width:3px,color:#fff
                    style C2 fill:#f5f7fa,stroke:#333,stroke-width:2px
                    style C3 fill:#f5f7fa,stroke:#333,stroke-width:2px
            </div>
        </div>

        <!-- Core Algorithm Card -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
            <div class="flex items-center justify-between mb-6">
                <div class="flex items-center">
                    <i class="fas fa-brain text-3xl text-purple-600 mr-4"></i>
                    <h2 class="text-3xl font-bold text-gray-800">核心算法</h2>
                </div>
                <span class="badge">双指针</span>
            </div>
            <div class="text-gray-700 leading-relaxed text-lg">
                <p class="mb-4">双指针算法是解决链表相交问题的经典方法，其核心思想是通过巧妙的指针移动策略，消除两个链表长度差异的影响。</p>
                <div class="bg-gradient-to-r from-purple-50 to-pink-50 rounded-lg p-6 border-l-4 border-purple-600">
                    <p class="font-semibold text-purple-800 mb-2"><i class="fas fa-lightbulb mr-2"></i>算法精髓</p>
                    <p class="text-gray-700">让两个指针分别遍历两个链表，当一个指针到达末尾时，切换到另一个链表的头部继续遍历。这样可以保证两个指针走过的总路径长度相同，如果存在交点，它们必然会在交点处相遇。</p>
                </div>
            </div>
        </div>

        <!-- Solution Steps -->
        <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
            <div class="bg-white rounded-2xl shadow-xl p-6 card-hover">
                <div class="flex items-center mb-4">
                    <i class="fas fa-route text-2xl text-purple-600 mr-3"></i>
                    <h3 class="text-xl font-bold text-gray-800">解题步骤</h3>
                </div>
                <ol class="space-y-3">
                    <li class="flex items-start">
                        <span class="bg-purple-600 text-white rounded-full w-6 h-6 flex items-center justify-center text-sm font-bold mr-3 flex-shrink-0">1</span>
                        <span class="text-gray-700">初始化两个指针分别指向两个链表头</span>
                    </li>
                    <li class="flex items-start">
                        <span class="bg-purple-600 text-white rounded-full w-6 h-6 flex items-center justify-center text-sm font-bold mr-3 flex-shrink-0">2</span>
                        <span class="text-gray-700">同时移动两个指针，每次前进一步</span>
                    </li>
                    <li class="flex items-start">
                        <span class="bg-purple-600 text-white rounded-full w-6 h-6 flex items-center justify-center text-sm font-bold mr-3 flex-shrink-0">3</span>
                        <span class="text-gray-700">当指针到达链表末尾，切换到另一链表头</span>
                    </li>
                    <li class="flex items-start">
                        <span class="bg-purple-600 text-white rounded-full w-6 h-6 flex items-center justify-center text-sm font-bold mr-3 flex-shrink-0">4</span>
                        <span class="text-gray-700">两指针相遇时即为交点，或同时为null</span>
                    </li>
                </ol>
            </div>

            <div class="bg-white rounded-2xl shadow-xl p-6 card-hover">
                <div class="flex items-center mb-4">
                    <i class="fas fa-clock text-2xl text-purple-600 mr-3"></i>
                    <h3 class="text-xl font-bold text-gray-800">复杂度分析</h3>
                </div>
                <div class="space-y-4">
                    <div class="bg-purple-50 rounded-lg p-4">
                        <div class="flex items-center justify-between mb-2">
                            <span class="font-semibold text-gray-700">时间复杂度</span>
                            <span class="text-purple-700 font-mono font-bold">O(n + m)</span>
                        </div>
                        <p class="text-sm text-gray-600">最多遍历两个链表各两次</p>
                    </div>
                    <div class="bg-pink-50 rounded-lg p-4">
                        <div class="flex items-center justify-between mb-2">
                            <span class="font-semibold text-gray-700">空间复杂度</span>
                            <span class="text-pink-700 font-mono font-bold">O(1)</span>
                        </div>
                        <p class="text-sm text-gray-600">只使用了两个指针变量</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Code Implementation -->
        <div class="bg-white rounded-2xl shadow-xl overflow-hidden mb-8 card-hover">
            <div class="bg-gradient-to-r from-purple-600 to-pink-600 text-white p-6">
                <div class="flex items-center">
                    <i class="fas fa-code text-3xl mr-4"></i>
                    <h2 class="text-2xl font-bold">示例代码</h2>
                </div>
            </div>
            <div class="code-block">
                <pre><code><span class="keyword">def</span> <span class="function">getIntersectionNode</span>(headA, headB):
    <span class="comment"># 处理边界情况</span>
    <span class="keyword">if not</span> headA <span class="keyword">or not</span> headB:
        <span class="keyword">return</span> <span class="keyword">None</span>
    
    <span class="comment"># 初始化两个指针</span>
    pa, pb = headA, headB
    
    <span class="comment"># 双指针遍历，直到相遇</span>
    <span class="keyword">while</span> pa != pb:
        <span class="comment"># 到达末尾则切换到另一个链表头</span>
        pa = pa.next <span class="keyword">if</span> pa <span class="keyword">else</span> headB
        pb = pb.next <span class="keyword">if</span> pb <span class="keyword">else</span> headA
    
    <span class="comment"># 返回交点（或None）</span>
    <span class="keyword">return</span> pa</code></pre>
            </div>
        </div>

        <!-- Key Insights -->
        <div class="bg-gradient-to-r from-purple-100 to-pink-100 rounded-2xl p-8">
            <div class="flex items-center mb-6">
                <i class="fas fa-star text-3xl text-purple-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">算法洞察</h2>
            </div>
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                <div class="bg-white rounded-lg p-6 text-center">
                    <i class="fas fa-balance-scale text-4xl text-purple-600 mb-4"></i>
                    <h3 class="font-bold text-gray-800 mb-2">路径平衡</h3>
                    <p class="text-gray-600 text-sm">通过交换链表，两指针走过的总路径长度相